package com.example.demo;


import com.example.demo.dao.BookDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*")
public class DemoController {
    @Autowired
    private BookDAO bookDAO;
    @RequestMapping("/say")
    public List<Lending> sayHello(){
        List<Lending> ret = new ArrayList<Lending>();
        ret.add(new Lending("0001", new Date(), "曹叡","平凡的世界"));
        ret.add(new Lending("0001", new Date(), "曹叡","人生"));
        ret.add(new Lending("0001", new Date(), "曹叡","Transaction Process"));
        return ret;

    }
    @RequestMapping(path="/queryBook")

    public List<Book> findBooks(@RequestBody Map<String, String> paras){
        return bookDAO.findBooks(paras.get("bookName"));
    }
    @RequestMapping(path="/update")
    public void updateBook(@RequestBody Book book){
        bookDAO.updateBook(book);

    }

    @RequestMapping(path="/delete")
    public void deleteBook(@RequestBody Map<String, String> paras){
        bookDAO.deleteBook(paras.get("id"));

    }
}
